package com.jelly.io.collect;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class OSExecute {
	public static void command(String command) {
		boolean err = false;
		try {
			Process process = new ProcessBuilder(command.split(" ")).start();
			BufferedReader result = new BufferedReader(new InputStreamReader(process.getInputStream()));
			String s ;
			while(null!=(s = result.readLine())){
				System.out.println(s);
			}
			BufferedReader erros = new BufferedReader(new InputStreamReader(process.getErrorStream()));
			while(null!=(s=erros.readLine())){
				System.err.println(s);
				err=true;
			}
			
		} catch (IOException e) {
			if(!command.startsWith("CMD /C")){
				command("CMD /C"+command);
			}else{
				throw new RuntimeException();
			}
			if(err){
				throw new OSExecuteException("Errors executing"+command);
			}
			e.printStackTrace();
			
		}
	}
}
